* (bug 22061) API: add prop=headitems to action=parse
authorSam Reed <reedy@users.mediawiki.org>
Sat, 16 Jan 2010 13:07:58 +0000 (13:07 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sat, 16 Jan 2010 13:07:58 +0000 (13:07 +0000)
Patch contributed by Paul Copperman

RELEASE-NOTES
includes/OutputPage.php
includes/api/ApiParse.php
includes/parser/ParserOutput.php

index 2f01595..3879f63 100644 (file)
@@ -787,6 +787,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Expand the thumburl to an absolute url to make it consistent with url and 
   descriptionurl 
 * (bug 20233) ApiLogin::execute() doesn't handle LoginForm :: RESET_PASS
+* (bug 22061) API: add prop=headitems to action=parse
 
 === Languages updated in 1.16 ===
 
index 3090e19..f1a368f 100644 (file)
@@ -605,7 +605,7 @@ class OutputPage {
                        $this->enableClientCache( false );
                }
                $this->mNoGallery = $parserOutput->getNoGallery();
-               $this->mHeadItems = array_merge( $this->mHeadItems, (array)$parserOutput->mHeadItems );
+               $this->mHeadItems = array_merge( $this->mHeadItems, $parserOutput->getHeadItems() );
                // Versioning...
                foreach ( (array)$parserOutput->mTemplateIds as $ns => $dbks ) {
                        if ( isset( $this->mTemplateIds[$ns] ) ) {
index b645798..ede03a4 100644 (file)
@@ -157,6 +157,10 @@ class ApiParse extends ApiBase {
                        $result_array['displaytitle'] = $p_result->getDisplayTitle() ?
                                                        $p_result->getDisplayTitle() :
                                                        $titleObj->getPrefixedText();
+               
+               if( isset( $prop['headitems'] ) )
+                       $result_array['headitems'] = $this->formatHeadItems( $p_result->getHeadItems() );                                       
+                                                       
                if ( !is_null( $oldid ) )
                        $result_array['revid'] = intval( $oldid );
 
@@ -169,6 +173,7 @@ class ApiParse extends ApiBase {
                        'images' => 'img',
                        'externallinks' => 'el',
                        'sections' => 's',
+                       'headitems' => 'hi'
                );
                $this->setIndexedTagNames( $result_array, $result_mapping );
                $result->addValue( null, $this->getModuleName(), $result_array );
@@ -212,6 +217,17 @@ class ApiParse extends ApiBase {
                return $result;
        }
 
+       private function formatHeadItems( $headItems ) {
+               $result = array();
+               foreach( $headItems as $tag => $content ) {
+                       $entry = array();
+                       $entry['tag'] = $tag;
+                       $this->getResult()->setContent( $entry, $content );
+                       $result[] = $entry;
+               }
+               return $result;
+       }
+
        private function setIndexedTagNames( &$array, $mapping ) {
                foreach ( $mapping as $key => $name ) {
                        if ( isset( $array[$key] ) )
@@ -242,6 +258,7 @@ class ApiParse extends ApiBase {
                                        'sections',
                                        'revid',
                                        'displaytitle',
+                                       'headitems'
                                )
                        ),
                        'pst' => false,
index 56fca3a..c7cae73 100644 (file)
@@ -50,6 +50,7 @@ class ParserOutput
        function &getImages()                { return $this->mImages; }
        function &getExternalLinks()         { return $this->mExternalLinks; }
        function getNoGallery()              { return $this->mNoGallery; }
+       function getHeadItems()              { return $this->mHeadItems; }
        function getSubtitle()               { return $this->mSubtitle; }
        function getOutputHooks()            { return (array)$this->mOutputHooks; }
        function getWarnings()               { return array_keys( $this->mWarnings ); }